package com.tjtt.tdm.util;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageHelper {

	/***
	 * 功能 :调整图片大小 开发：wuyechun 2011-7-22
	 * @param srcImgPath 原图片路径
	 * @param distImgPath  转换大小后图片路径
	 * @param width   转换后图片宽度
	 * @param height  转换后图片高度
	 */
	public static void resizeImage(String srcImgPath, String distImgPath,
			int width, int height) throws IOException {

		File srcFile = new File(srcImgPath);
		Image srcImg = ImageIO.read(srcFile);
		BufferedImage buffImg = null;
		buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		buffImg.getGraphics().drawImage(
				srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
				0, null);

		ImageIO.write(buffImg, "JPEG", new File(distImgPath));

	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
        BufferedImage image;
		try {
			ImageHelper.resizeImage("D:\\Hydrangeas.jpg","D:\\Hydrangeas.jpg", 400, 300);   
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	}

}
